package org.thesis.adapter;

import java.util.List;

import org.thesis.doituong.templates_sub;

import uit.mmt02.R;

import android.app.Activity;
import android.content.Intent;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class templates_sub_adapter extends ArrayAdapter<templates_sub> 
{
	final static String KEY_SUB_TEMP = "SUB TEMPLATES";
	List<templates_sub>list;
	Activity context;
	int location;
	public templates_sub_adapter(Activity context, List<templates_sub>list)
	{
		super(context, R.layout.row_templates_sub,list);
		this.context = context;
		this.list = list;
	}
	@Override
	public View getView(int position, View convertView, ViewGroup parent) 
	{
		// TODO Auto-generated method stub
		location = position;
		View v = null;
		if(convertView == null)
		{
			LayoutInflater layoutInflater = context.getLayoutInflater();
			v = layoutInflater.inflate(R.layout.row_templates_sub, null);
		}
		else
			v = convertView;
		final templates_sub sub = list.get(position);
		TextView txtstt = (TextView) v.findViewById(R.id.txt_stt);
		TextView txtmessage = (TextView) v.findViewById(R.id.txt_message);
		
		txtstt.setText(String.valueOf(sub.getId()));
		txtmessage.setText(sub.getMessage());
		v.setOnClickListener(new OnClickListener() {
			
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				Log.v("adapter sub", "cham nhe ^^");
				Intent data = new Intent();
				data.putExtra(KEY_SUB_TEMP, sub.getMessage());
				context.setResult(context.RESULT_OK, data);
				context.finish();
			}
		});
		return v;
	}
}
